﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace winformApplication
{
    public abstract class Operation
    {

        protected double opA;
        protected double opB;

        protected Operation(double opA,double opB)
        {
            this.opA = opA;
            this.opB = opB;
        }       

        abstract public double getResult();
    }

    public class OperationAdd : Operation
    {
        public OperationAdd(double opA, double opB) : base(opA,opB)
        {           
        }
        public override double getResult()
        {
            return opA + opB;
        }
    }

    public class OperationSub : Operation
    {

        public OperationSub(double opA, double opB) : base(opA,opB)
        {
        }
        public override double getResult()
        {
            return opA - opB;
        }
    }

    public class OperationMulti : Operation
    {

        public OperationMulti(double opA, double opB) : base(opA, opB)
        {
        }
        public override double getResult()
        {
            return opA * opB;
        }
    }

    public class OperationDevide : Operation
    {

        public OperationDevide(double opA, double opB) : base(opA, opB)
        {
        }
        public override double getResult()
        {
            if(opB == 0)
            {
                throw new Exception("除数为0!");
            }
            return opA / opB;
        }
    }

    public class OperationPow : Operation
    {

        public OperationPow(double opA, double opB) : base(opA, opB)
        {
        }
        public override double getResult()
        {
            return Math.Pow(opA, opB);          
        }
    }
}
